﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 依赖反转
{
    public class Program
    {
        static void Main(string[] args)
        {
            PowerSupply power = new PowerSupply();
            DeskFan desk = new DeskFan(power);
            string msg = desk.Work();
            Console.WriteLine(msg);

            Console.ReadKey();
        }
    }

    public interface IPowerSupply
    {
        int GetPower();
    }

    public class PowerSupply : IPowerSupply
    {
        public int GetPower()
        {
            return 100;
        }
    }

    public class DeskFan
    {
        private IPowerSupply _powerSupply;

        public DeskFan(IPowerSupply powerSupply)
        {
            _powerSupply = powerSupply;
        }

        public String Work()
        {
            int power = _powerSupply.GetPower();
            if (power < 0)
            {
                return "不工作";
            }
            else if (power < 100)
            {
                return "慢";
            }
            else if (power < 200)
            {
                return "正常工作";
            }
            else
            {
                return "警报";
            }
        }
    }
}
